/**
 * 
 */
package club325.webchat.database.hibernate.implement;

import org.hibernate.Query;

import club325.webchat.database.hibernate.dao.HibernateUtil;
import club325.webchat.database.hibernate.dao.PersonalInfoDAO;
import club325.webchat.database.hibernate.domain.PersonalInfo;

/**
 * @author Sider
 *
 */
public class PersonalInfoImplement implements PersonalInfoDAO
{

	/* (non-Javadoc)
	 * @see club325.webchat.database.hibernate.dao.PersonalInfoDAO#savePersonalInfo(club325.webchat.database.hibernate.domain.PersonalInfo)
	 */
	public void savePersonalInfo(PersonalInfo perinfo)
	{
		HibernateUtil.add(perinfo);
	}

	/* (non-Javadoc)
	 * @see club325.webchat.database.hibernate.dao.PersonalInfoDAO#deletePersonalInfo(club325.webchat.database.hibernate.domain.PersonalInfo)
	 */
	public void deletePersonalInfo(PersonalInfo perinfo)
	{
		HibernateUtil.delete(perinfo);
	}

	/* (non-Javadoc)
	 * @see club325.webchat.database.hibernate.dao.PersonalInfoDAO#findPersonalInfobyID(int)
	 */
	public PersonalInfo findPersonalInfobyID(int id)
	{
		return (PersonalInfo)HibernateUtil.get(PersonalInfo.class, id);
	}

	/* (non-Javadoc)
	 * @see club325.webchat.database.hibernate.dao.PersonalInfoDAO#findPersonalInfobymemberID(java.lang.String)
	 */
	public PersonalInfo findPersonalInfobymemberID(String memberID)
	{
		String HQL = "FROM PersonalInfo as perinfo WHERE perinfo.memberID = ?";
		Query q = HibernateUtil.getSession().createQuery(HQL);
		q.setString(0, memberID);
		return (PersonalInfo)q.uniqueResult();
	}

	public void updatePersonalInfo(PersonalInfo perinfo)
	{
		HibernateUtil.Update(perinfo);
	}

}
